<template>
    <view class="edit-name">
		<!-- #ifdef H5 -->
		<uni-nav-bar dark left-icon="left" :fixed="true" :right-text="options.level!=1?'保存':''" title="群公告" background-color="#fff" color="#262E3F"  @clickLeft="utils.goBack()" @clickRight="keep()" />
		<!-- #endif -->
        <view class="input-box">
			<textarea type="text" auto-height placeholder-style="color:#aaa"  :disabled="options.level!=1?false:true" :placeholder="options.level!=1?'填写群公告':'暂无群公告'" :value="inputText" @input="input" ></textarea>
		</view>
        <view class="module" v-if="options.level!=1">
			<view class="title">
				<text>群公告模板</text>
				<text @click="inputText=defaultCont">一键填写</text>
			</view>
			<view class="content" v-html="defaultCont">
			</view>	
		</view>
    </view>
</template>
<script>
export default {
    data() {
        return{
            inputText: '',
            options: {},
			defaultCont:`1.本群提倡友好理性交流，鼓励同学们多发言，多互动；
2.禁止无意义刷屏、谩骂等不良消息`
        } 
    },
    onNavigationBarButtonTap(e){
        this.keep()
    },
    onLoad(options){
        this.options = options;
		this.getfindUserIdentity()
    },
	onShow(){
		// #ifndef H5
		this.$nextTick(()=>{
			let currentWebview = this.$scope.$getAppWebview()
			let titleObj = currentWebview.getStyle().titleNView;
			if(this.options.level==1){
				titleObj.buttons[0].text = '';
			}else{
				titleObj.buttons[0].text = '保存';
			}
			currentWebview.setStyle({
				titleNView: titleObj
			});
		})
		// #endif
	},
    methods: {
        keep(){
            // 保存
			if(this.options.level==1)return;
			let str = this.inputText.trim()
            if(!str){
				this.utils.showToast('群公告不能为空')
                return
            }
            this.api.post('chatGroupManage/updateChatGroupData', {
                chatGroupId: this.options.id,
                notice: this.inputText,
            }).then(res=>{
				if(res.data.state != 'ok') return;
				this.utils.showToast('保存成功')
            })
        },
		getfindUserIdentity(){
			this.api.get('chatGroupManage/getGroupNotice', {
				chatGroupId: this.options.id
			}).then(res=>{
				if(res.data.state != 'ok') return;
				this.inputText = res.data.notice;
			})
		},
        input(e){
            this.inputText = e.detail.value;
        },
        clearIcon(){
            this.inputText = ''
        }
    }
}
</script>
<style lang="less" scoped>
	.input-box{
		background-color: #fafafa;
		margin: 40rpx 32rpx;
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
		textarea{
			font-size: 28rpx;
			width: 100%;
			min-height: 292rpx;
		}
	}
	.module{
		margin: 0 32rpx;
		color: #7f7f7f;
		font-size: 24rpx;
		.title{
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
		.content{
			margin-top: 16rpx;
			line-height: 36rpx;
			white-space: pre-line;
		}
	}
</style>